package assignment02;

import java.util.List;

import nlp.classify.LabeledInstance;
import nlp.langmodel.LanguageModel;
import nlp.util.Counter;

public class QuagramLanguageModel implements LanguageModel {

	private static final double INCREMENT = 1.0;
	private final Character START = '\uE000';
	private final Character STOP = '\uE001';
	private final Character UNKNOWN = '\uE002';
	private Counter<String> featureCounter = new Counter<String>();
	private List<LabeledInstance<String, String>> trainingData;
	private List<LabeledInstance<String, String>> validationSet;
	
	public QuagramLanguageModel(List<LabeledInstance<String, String>> trainingData) {
		this.trainingData = trainingData;
	    for (LabeledInstance<String, String> testDatum : trainingData) {
	    	String input = testDatum.getInput();
	    	ngramFeature(input);
	    	suffixFeature(input);
	    	lengthFeature(input);
	    }
	}
	
	protected void ngramFeature(String noun) {
		char[] characters = noun.toCharArray();
		for (int i = 0; i < characters.length - 2; i++) {
			Character previous = characters[i];
			Character current = characters[i+1];
			Character next = characters[i+2];
			String trigramFeature = "TRI" + previous + current + next;
			featureCounter.setCount(trigramFeature, INCREMENT);
		}
	}
	
	protected void suffixFeature(String noun) {
		String words[] = noun.split("[ \t\n\r]");
		String suffixFeature = "SUFFIX" + words[words.length - 1];
		featureCounter.setCount(suffixFeature, INCREMENT);
		numOfWordsFeature(words);
	}
	
	private void numOfWordsFeature(String[] words) {
		String numFeature = "#WORDS" + words.length;
		featureCounter.setCount(numFeature, INCREMENT);
	}
	
	protected void lengthFeature(String noun) {
		String lengthFeature = "LENGTH" + noun.length();
		featureCounter.setCount(lengthFeature, INCREMENT);
	}
	
	@Override
	public double getSentenceProbability(List<String> sentence) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<String> generateSentence() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public static void main(String[] args) {
		String a = "abc";
		String words[] = a.split("[ \t\n\r]");
		System.out.println(words.length);
	}

}
